<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <link rel="stylesheet" href="/web/res/wangEditor/wangEditor.css">

    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
</head>

<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">
    <form class="layui-form layui-form-pane" id="formsubmit" lay-filter="formsubmit"
          style="width: 500px;margin:20px auto" action="/after/help/saveOrUpdate">
        <input type="hidden" id="id" name="id" value="${(help.id?c)!''}">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="${(help.title?html)!''}" required
                       lay-verify="required" autocomplete="off" class="layui-input"/>
            </div>
        </div>

            <div class="layui-form-item">
                <label class="layui-form-label">消息内容</label>
                <div class="layui-input-block">
                    <div id="editor1" style="width: 200%">
                    </div>
                </div>
            </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">问题类型</label>
                <div class="layui-input-block">
                    <select name="type" id="type" lay-filter="type" lay-verify="required" style="margin: 0;">
                        <option value="1"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 1?number>selected</#if></#if>>常见问题
                        </option>
                        <option value="2"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 2?number>selected</#if></#if>>账号问题
                        </option>
                        <option value="3"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 3?number>selected</#if></#if>>钻石问题
                        </option>
                        <option value="4"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 4?number>selected</#if></#if>>认证问题
                        </option>
                        <option value="5"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 5?number>selected</#if></#if>>金币问题
                        </option>
                        <option value="6"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 6?number>selected</#if></#if>>热门问题
                        </option>
                        <option value="7"
                        <#if help?exists && help.type?exists><#if (help.type)?number == 7?number>selected</#if></#if>>其他
                        </option>
                    </select>
                </div>
            </div>
        </div>

            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="text" name="sort" value="${(help.sort?html)!''}" required
                           lay-verify="required" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <input id="content" name="content" type="hidden">

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">
                        &emsp;保存&emsp;
                    </button>
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
                        &emsp;返回&emsp;
                    </button>
                </div>
            </div>
    </form>
    <div/>
    <script type="text/javascript" src="/web/res/wangEditor/wangEditor.js"></script>
    <script>
        layui.use(['form', 'upload'], function () {
            let $ = layui.$;
            var form = layui.form;
            var upload = layui.upload;
            form.render();

            // 重新添加删除功能
            $('.upload-cancel').on('click',(event)=> {
                let self = $(event.currentTarget);
            self.parent().remove();
            event.stopPropagation();
            if ($("input[id='imgpathhide']").length < 1) {
                $('#uploadtemplate').show();
            } else {
                $('#uploadtemplate').hide();
            }
        })
            ;

            $.fn.extend({
                serializeObject: function () {
                    var obj = {}; //声明一个对象
                    $.each(this.serializeArray(), function (index, field) {
                        obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                    })
                    return obj;
                }
            });
            form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {
                console.log(data);

                layer.confirm('确认要保存吗？', function (index) {
                    var str1 = editor1.txt.html();
                    $("#content").val(str1);
                    ajaxPost($, $("#formsubmit").attr("action"), $("#formsubmit").serializeObject(), function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 3000}, function () {
                                xadmin.close();
                            });
                        }
                    });
                });
            });

        });
        var E = window.wangEditor;
        var editor1 = new E('#editor1');
        editor1.customConfig.uploadImgServer = '/after/setup/setupUpload';
        editor1.customConfig.uploadFileName = 'myFileName';
        editor1.customConfig.uploadImgHooks = {
            before: function(xhr, editor, files) {
            },
            success: function(xhr, editor, result) {
                var num=$("#graphics").val();
                $("#graphics").val("");
                $("#graphics").val(parseInt(num)+1);
                var url=$("#imageUrl").val();
                console.log(url);
                console.log(url=='');
                if(url==''){
                    $("#imageUrl").val(result.data[0]);
                }else{
                    $("#imageUrl").val(url+","+result.data[0]);
                }
                console.log("上传成功");
            },
            fail: function(xhr, editor, result) {

                console.log("上传失败,原因是" + result);
            },
            error: function(xhr, editor) {
                console.log("上传出错");
            },
            timeout: function(xhr, editor) {
                console.log("上传超时");
            }
        };
        editor1.create();
        editor1.txt.html('${help.content!''}');
    </script>
</body>

</html>